package com.travel.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.travel.dao.AdminDao;
import com.travel.entity.Admin;
import com.travel.util.DBUtils;

public class AdminDaoImpl implements AdminDao{

	private DBUtils db = new DBUtils();
	
	@Override
	public List<Admin> findByNameAndPassword(String adminName, String adminPassword) {
		String sql = "select admin_id,admin_name,admin_password from tab_admin where admin_name=? and admin_password=?";
		ResultSet rs = db.query(sql, adminName,adminPassword);
		List<Admin> list = new ArrayList<Admin>();
		
		try {
			while (rs.next()) {
				int adminId = rs.getInt("admin_id");
				adminName = rs.getString("admin_name");
				adminPassword = rs.getString("admin_password");
				Admin admin = new Admin(adminId, adminName, adminPassword);
				list.add(admin);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

}
